//
//  RWNetworkResponse.h
//  RWNetwork
//
//  Created by Ray on 2024/4/25.
//  Copyright © 2024 81SK. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface RWNetworkResponse : NSObject

/// 请求成功数据,  下载时是:NSURL
@property (nonatomic, strong, readonly, nullable) id responseObject;
/// 请求成功数据,  下载时是:NSURL（源数据）
@property (nonatomic, strong, readonly, nullable) id sourceObject;
/// 请求失败 NSError
@property (nonatomic, strong, readonly, nullable) NSError *error;
/// 请求任务
@property (nonatomic, strong, readonly, nullable) NSURLSessionTask *sessionTask;
/// sessionTask.response
@property (nonatomic, strong, readonly, nullable) NSHTTPURLResponse *urlResponse;
/// 是否是缓存数据
@property (nonatomic, assign, readonly) BOOL isCache;

/// 序列化NSURLRequest错误 或 本地错误
+ (instancetype)responseWithError:(NSError *)error;

/// 快速构造-网络
/// @param data 缓存的数据
+ (instancetype)responseWithCache:(nullable id)data;

/// 快速构造--网络
/// - Parameters:
///   - data: 服务端返回的response
///   - sessionTask: NSURLSessionTask可以获取NSURLResponse
///   - error: 网络error
+ (instancetype)responseWithData:(nullable id)data task:(nullable NSURLSessionTask *)sessionTask error:(nullable NSError *)error;

- (void)refreshData:(id)data;

@end

NS_ASSUME_NONNULL_END
